package com.duolaibei.pay.activity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.duolaibei.pay.R;
import com.duolaibei.pay.base.BaseActivity;
import com.duolaibei.pay.base.Constants;
import com.duolaibei.pay.smscan.SunmiScanActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import java.util.HashMap;
import java.util.Map;

import butterknife.ButterKnife;
import pub.devrel.easypermissions.EasyPermissions;

/**
 * Created by guohaicheng1993 on 2017/5/14.
 */


public class SweepManageActivity extends BaseActivity {

    private LinearLayout detailLayout;//交易明细
    private LinearLayout reimburseLayout;//扫码退款
    private LinearLayout checklistLayout;//扫码查单
    private LinearLayout settlementLayout;//结算
    private Button btsure;
    private TextView ttprompt;

    private AlertDialog dialog = null;


    private final int REQUEST_CODE = 100;
    private final int CAMERA_CODE = 0;
    private Map<String, String> params;

    @Override
    public int getContentViewResId() {
        return R.layout.activity_sweepmg;
    }

    @Override
    public void intiViews() {
        params = new HashMap<>();
        detailLayout = (LinearLayout) findViewById(R.id.detail_layout);
        reimburseLayout = (LinearLayout) findViewById(R.id.reimburse_layout);
        checklistLayout = (LinearLayout) findViewById(R.id.checklist_layout);
        settlementLayout = (LinearLayout) findViewById(R.id.settlement_layout);

//        detailLayout.setOnClickListener(this);
        reimburseLayout.setOnClickListener(this);
        checklistLayout.setOnClickListener(this);
        settlementLayout.setOnClickListener(this);

    }

    @Override
    public String setTitle() {
        return "扫码管理";
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        int id = view.getId();
        Intent intent = null;
        switch (id) {
//            case R.id.detail_layout:
//                intent = new Intent(this, TransactionActivity.class);
//                break;
            case R.id.reimburse_layout:
                String[] perms = {Manifest.permission.CAMERA};
                if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限
                    Intent qrIntent = new Intent(this, SunmiScanActivity.class);
                    qrIntent.putExtra("type", 300);
                    qrIntent.putExtra("title", getString(R.string.sweep_back_money));
                    startActivityForResult(qrIntent, REQUEST_CODE);
                } else {
                    EasyPermissions.requestPermissions(this, getString(R.string.get_permissions_tips), CAMERA_CODE, perms);
                }
                break;
            case R.id.checklist_layout:
                String[] perms1 = {Manifest.permission.CAMERA};
                if (EasyPermissions.hasPermissions(this, perms1)) {//检查是否获取该权限
                    Intent qrIntent = new Intent(this, SunmiScanActivity.class);
                    qrIntent.putExtra("title", getString(R.string.sweep_select_deal));
                    qrIntent.putExtra("type", 100);
                    startActivity(qrIntent);
                } else {
                    EasyPermissions.requestPermissions(this, getString(R.string.get_permissions_tips), CAMERA_CODE, perms1);
                }
                break;
            case R.id.settlement_layout:
//                dialog = new AlertDialog.Builder(SweepManageActivity.this, R.style.dialog_style).create();
//                dialog.show();
//                dialog.getWindow().setContentView(R.layout.mydialog);
//                dialog.getWindow().findViewById(R.id.sure_bt).setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//
//                        dialog.getWindow().setContentView(R.layout.mydialog_next);
//                    }
//                });
                Intent intent1 = new Intent(this, SweepGatheringActivity.class);
                startActivity(intent1);
                break;
        }

        if (null != intent) {
            startActivity(intent);
        }
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE) {
            //处理扫描结果（在界面上显示）
            if (null != data) {
                Bundle bundle = data.getExtras();
                if (bundle == null) {
                    return;
                }
                if (bundle.getInt(Constants.SCAN_STATE) != 0) {
                    String result = bundle.getString(Constants.SCAN_CONTENT);
                } else if (bundle.getInt(Constants.SCAN_STATE) == 0) {
                    Toast.makeText(this, "解析二维码失败", Toast.LENGTH_LONG).show();
                }
            }
        }
    }
}
